// 搜索业务

// 先拿到地址栏的参数
const keyStr = yzb.getUrlValue('keyWord');
const keyWord = decodeURI(keyStr);

(function() {
	let oSearchItems = document.querySelector('.search-items');

	// 请求后台
	yzb.ajax({
		url: BASE_URL + '/api_search',
		data: {
			pagesize:12,
			keywords: keyWord
		},
		success(res) {
			if (res.code != 0) {
				console.log(res);
				return;
			};
			// 渲染到页面
			let data = res.data;
			console.log(data);
			let str = '';
			data.forEach(item => {
				str += `
				<div class="goodsItem">
					<div class="brand-item">
						<a href=""><img src="${item.brand_thumb}" /></a>
						<div class="brand-name">
							<a href="">${item.brand_name}</a>
							<a href="">${item.star_number}</a>
						</div>
					</div>
					<div class="itemImg">
						<img src="${item.goods_thumb}" />
						<a href="goods.html?catId=${item.cat_id}&goodsId=${item.goods_id}" class="search-cover">
							<div class="item-price">
								<span>￥${item.price}</span>
								<span></span>
							</div>
							<div class="itemDes">
								${item.goods_name}
							</div>
						</a>
					</div>
				</div>
				
				<div class="marginR"></div>
				`;
			});
			// 添加到页面
			oSearchItems.innerHTML = str;
		}
	})

})();